package com.mavenq.fly.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mavenq.fly.business.entity.Family;
import com.mavenq.fly.business.entity.Goods;
import com.mavenq.fly.business.entity.GoodsDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController{

   /* {
        "goodsName": "pingguo",
            "goodsCode": "apple",
            "tags": [
        {
            "name": "haochi"
        },
        {
            "name": "haowan"
        }
  ],
        "id": 1,
            "goodsDetail": {
        "goodsName": "taozi",
                "goodsCode": "pic",
                "desc": "taozihaochi",
                "tags": [
        {
            "name": "haochi-1"
        },
        {
            "name": "haowan-1"
        }
    ]
    }
    }*/
    @RequestMapping("/testCopy")
    public Object testCopy(@RequestBody Goods goods) throws Exception{
        GoodsDetail goodsDetail = new GoodsDetail();
        BeanUtils.copyProperties(goods, goodsDetail);
        System.out.println("1"+JSONObject.toJSONString(goodsDetail));
        BeanUtils.copyProperties(goods.getGoodsDetail(), goodsDetail);
        System.out.println("2"+JSONObject.toJSONString(goodsDetail));

        //1{"goodsCode":"apple","goodsName":"pingguo","id":1,"tag":{"name":"e"},"tags":[{"name":"haochi"},{"name":"haowan"}]}
        //2{"desc":"taozihaochi","goodsCode":"pic","goodsName":"taozi","id":1,"tag":{"name":"e"},"tags":[{"name":"haochi-1"},{"name":"haowan-1"}]}
        return null;
    }

}
